﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL.Exceptions
{
    public class DALException : Exception
    {
        private const string k_PreMessage = "DALException: ";

        public DALException(string message)
            :base(message) {}

        public override string Message
        {
            get
            {
                return string.Format("{0} {1}\n", k_PreMessage, base.Message);
            }
        }
    }

    public class CommonMessagesGenerator
    {
        public static string GenerateNotExistObjectMessage(string objectType, string objectId, string additionalInfo)
        {
            if(additionalInfo == null)
            {
                additionalInfo = string.Empty;
            }
            return string.Format("{0} with id {1} is not exist {2}", objectType, objectId, additionalInfo);  
        }

        public static string GenerateNotExistObjectMessage(string firstObjectType, string firstObjectId, 
            string secondObjectType, string secondObjectId, string additionalInfo)
        {
            if (additionalInfo == null)
            {
                additionalInfo = string.Empty;
            }
            return string.Format("{0} with id {1} or {2} with id {3} are not exist {4}", firstObjectType, firstObjectId,
                secondObjectType, secondObjectId, additionalInfo);
        }

        public static string GenerateAllreadyExistObjectMessage(string objectType, string objectId, string additionalInfo)
        {
            if (additionalInfo == null)
            {
                additionalInfo = string.Empty;
            }
            return string.Format("{0} with id {1} is allready exist {2}", objectType, objectId, additionalInfo);
        }

        public static string GenerateDBException(string originalExceptionMessage, string methodName)
        {
            return string.Format("DB exception thrown in {0}: {1}", methodName, originalExceptionMessage);
        }
    }
}
